package com.coder520.sync_learning.demo;

import java.util.concurrent.TimeUnit;

public class ThreadIntertupted {
    /**
     * 如果一个线程设置了interrupt标识，那么接下来的可中断方法会立即中断，因此会获取到
     * exception
     * @param args
     */
    public static void main(String[] args){
        //判断当前线程是否终中断
        System.out.println("main thread is interrupted?"+Thread.interrupted());
        //中断当前的线程
        Thread.currentThread().interrupt();
        //判断当前线程是否终中断
        System.out.println("main thread is interrupted?"+Thread.currentThread().isInterrupted());

        try {
            //当前线程执行可中断
             TimeUnit.MINUTES.wait(1);
        }catch (Exception e){
            System.out.println("I will be interrupted still");
        }
    }
}
